class RandomizedSet {
public:
    unordered_map<int, int>m;//value->index
    int index = 1;
    vector<int>arr;
    RandomizedSet() {
        arr.push_back(0);
    }

    bool insert(int val) {
        if (m[val]) { return false; }
        else {
            m[val] = index;
            index++;
            arr.push_back(val);
            return true;
        }
    }

    bool remove(int val) {
        if (!m[val]) { return false; }
        else {
            m[arr.back()] = m[val];
            arr[m[val]] = arr.back();
            arr.pop_back();
            m.erase(val);
            index--;
            return true;
        }
    }

    int getRandom() {
        int answer = arr[rand() % (index-1)+1];
        return answer;
    }
};